import os
from datetime import datetime, timedelta
from config import (basic_values_type, 
                    basic_values_subtype, 
                    delta_day_default)


def check_folder(folder_path:str) -> None:
    """
    Function which is dedicated to develop values of it
    Input:  folder_path = path to the selected values
    Output: folder was created if it doesen't exists
    """
    os.path.exists(folder_path) or os.mkdir(folder_path)

def proceed_error(message:str) -> None:
    """
    Function which is dedicated to make the message that 
    Input:  message = message which is dedicated to make the error
    Output: we developed values of the
    """
    from telegram.telegram_supplementary import send_message_problem
    send_message_problem(message, True)

def make_default_datetime() -> object:
    """
    Function which is dedicated to return datetime for the tasks and the 
    Input:  None
    Output: we developed datetime values for it
    """
    return datetime.utcnow()

def make_default_datetime_finish(delta_day:int=delta_day_default, datetime_old:object=datetime.utcnow()) -> object:
    """
    Function which is dedicated to remove values of the 
    Input:  delta_day = day of the delta
    Output: we developed day for the finishing
    """
    return datetime_old + timedelta(days=delta_day)

def produce_message_text_description(value_query:set, accept:int) -> set:
    """
    Function for develop the description values of the text description
    Input:  value_query = values from the text
            accept = type of the task
    Output: string of the description and the message of it 
    """
    if accept == 1:
        id_task, id_message, date_start, date_end, description, types, subtypes = value_query
        date_start = datetime.strptime(date_start, '%Y-%m-%d %H:%M:%S.%f')
        date_end = datetime.strptime(date_end, '%Y-%m-%d %H:%M:%S.%f')
        msg = f"Id of the task: `{id_task}`\n"\
            f"Description of this task: \n`{description}`\n"\
            f"Datetime when it was created: `{datetime.strftime(date_start, '%Y-%m-%d %H:%M:%S')}`\n"\
            f"Datetime when it would end: `{datetime.strftime(date_end, '%Y-%m-%d %H:%M:%S')}`\n"\
            f"Type of this task: `{types}`\n"\
            f"Subtype of this task: `{subtypes}`"
    elif accept == 2:
        id_task, id_message, date_start, date_end, description, types, subtypes = value_query
        date_start = datetime.strptime(date_start, '%Y-%m-%d %H:%M:%S.%f')
        date_end = datetime.strptime(date_end, '%Y-%m-%d %H:%M:%S.%f')
        msg = f"Id of the task: `{id_task}`\n"\
            f"Description of this task: \n`{description}`\n"\
            f"Datetime when it was created: `{datetime.strftime(date_start, '%Y-%m-%d %H:%M:%S')}`\n"\
            f"Datetime when it expired: `{datetime.strftime(date_end, '%Y-%m-%d %H:%M:%S')}`\n"\
            f"Type of this task: `{types}`\n"\
            f"Subtype of this task: `{subtypes}`"
    elif accept == 3:
        id_task, id_message, date_start, date_end, desc_start, desc_finish, types, subtypes = value_query
        date_start = datetime.strptime(date_start, '%Y-%m-%d %H:%M:%S.%f')
        date_end = datetime.strptime(date_end, '%Y-%m-%d %H:%M:%S.%f')
        msg = f"Id of the task: `{id_task}`\n"\
            f"Description of this task: \n`{desc_start}`\n"\
            f"Description when you finished: \n`{desc_finish}`\n"\
            f"Datetime when it was created: `{datetime.strftime(date_start, '%Y-%m-%d %H:%M:%S')}`\n"\
            f"Datetime when it expired: `{datetime.strftime(date_end, '%Y-%m-%d %H:%M:%S')}`\n"\
            f"Type of this task: `{types}`\n"\
            f"Subtype of this task: `{subtypes}`"
    return msg, id_message

def proceed_new_name_type_subtype(value_inserted_list:list, value_inserted_name:str) -> str:
    """
    Function which is dedicated to develop new_name which would be inserted
    Input:  value_inserted_list = list of selected types by user
            value_inserted_name = string which would be inserted
    Output: we got values which would be inserted
    """
    if value_inserted_name not in value_inserted_list:
        return value_inserted_name
    return proceed_new_name_type_subtype(value_inserted_list, f"{value_inserted_name}(Copy)")

def proceed_insertion_type_subtype() -> set:
    """
    Function which is dedicated to develop insertion of the type & subtype in basic concepts
    Input:  Previously selected values of it
    Output: we developed set of the three values of the insertion to it
    """
    values_type = [[i.get('id'), i.get('name')] for i in basic_values_type]
    values_subtype = [[i.get('id'), i.get('name')] for i in basic_values_subtype]
    values_type_subtype = []
    for i, _ in values_type:
        for j, _ in values_subtype:
            values_type_subtype.append([i, j])
    return values_type, values_subtype, values_type_subtype

def get_filtration_tasks(value_task:list, value_present:list) -> list:
    """
    Function which is dedicated to get filtration of the tasks which is required
    Input:  value_task = tasks which were previously taken
            value_present = presented tasks for all of it
    Output: developed tasks of the sub tasks
    """
    task_return = []
    for i, *other in value_task:
        if i in value_present:
            returnal = [i]
            returnal.extend(other)
            task_return.append(returnal)
    return task_return